package com.fz.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by webrx on 2017-09-05.
 */
@Controller
public class Hello {
@RequestMapping("/test") @ResponseBody
    public void zz(){
        System.out.println("hello");
    }
@RequestMapping("/user.action") @ResponseBody
    public void user(HttpServletResponse resp, HttpServletRequest req) throws IOException {
        resp.setContentType("text/html;charset=utf-8");
        req.setCharacterEncoding("utf-8");

    PrintWriter out=resp.getWriter();
    out.print("我是一个中国人");
    out.flush();
    out.close();
    }

@RequestMapping("/info")
    public ModelAndView info(ModelAndView mv){
        mv.setViewName("info");
        mv.addObject("name","zhuang");
        mv.addObject("age",45);
        return mv;
    }
@RequestMapping("/bang")
    public String show(Model m){
        m.addAttribute("name","zhangsan");
        return "bang";
    }
}
